package com.itheima.mvc;

import com.itheima.interceptor.DemoInterceptor;
import com.itheima.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/***
 * 注册拦截器
 */
@Component
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private DemoInterceptor demoInterceptor;

    @Autowired
    private TokenInterceptor tokenInterceptor;

    //注册自定义拦截器对象
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /*registry.addInterceptor(demoInterceptor)
                .addPathPatterns("/**");//设置拦截器拦截的请求路径（ /** 表示拦截所有请求）*/
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/login");
    }
 }